<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description: 通用方法
 *
 *
 * @author      Eden
 * @datetime    2016/11/26 22:38
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

class General extends ADM_Controller
{


    /**
     * 上传
     */
    public function upload()
    {
        $send['state'] = false;
        do {
            if ($this->input->method(true) !== 'POST') {
                $send['error'] = '非法请求';
                break;
            }

            $width = 0;
            $height = 0;

            if ($w = $this->input->get('width')) {
                $width = intval($w);
            }

            if ($h = $this->input->get('height')) {
                $height = intval($h);
            }

            try {
                $res = local($_FILES['file']);
                if ($res) {
                    $res = array_merge($res, array('fullPath' => thumb($res['key'], $width, $height)));
                    $send['state'] = true;
                    $send['data'] = $res;
                }
            } catch(Exception $e) {

            }

        } while(false);
        $this->output->send($send);
    }
}
